﻿CREATE PROCEDURE [dbo].[yaf_user_deleteold](
                @BoardID INT)
AS
    BEGIN
        DECLARE  @Since DATETIME
        SET @Since = Getdate()
        DELETE FROM yaf_EventLog
        WHERE       UserID IN (SELECT UserID
                   FROM   yaf_User
                   WHERE  BoardID = @BoardID
                   AND dbo.yaf_bitset(Flags,2) = 0
                   AND Datediff(DAY,Joined,@Since) > 2)
        DELETE FROM yaf_CheckEmail
        WHERE       UserID IN (SELECT UserID
                   FROM   yaf_User
                   WHERE  BoardID = @BoardID
                   AND dbo.yaf_bitset(Flags,2) = 0
                   AND Datediff(DAY,Joined,@Since) > 2)
        DELETE FROM yaf_UserGroup
        WHERE       UserID IN (SELECT UserID
                   FROM   yaf_User
                   WHERE  BoardID = @BoardID
                   AND dbo.yaf_bitset(Flags,2) = 0
                   AND Datediff(DAY,Joined,@Since) > 2)
        DELETE FROM yaf_User
        WHERE       BoardID = @BoardID
        AND dbo.yaf_bitset(Flags,2) = 0
        AND Datediff(DAY,Joined,@Since) > 2
    END


